using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace SharpGraphT.Sharp.Util;

public static class Collections {

    public static IReadOnlySet<T> GetEmptyReadOnlySet<T>() => new EmptySet<T>();

    [Serializable]
    public class EmptySet<TE> : ISet<TE>, IReadOnlySet<TE> {
        private static readonly long SerialVersionUid = 1582296315990362920L;

        IEnumerator IEnumerable.GetEnumerator() {
            return GetEnumerator();
        }

        public IEnumerator<TE> GetEnumerator() =>
            Enumerable.Empty<TE>().GetEnumerator();

        void ICollection<TE>.Add(TE item) => throw new NotSupportedException();

        public void Clear() => throw new NotSupportedException();

        public bool Contains(TE item) => false;

        public void CopyTo(TE[] array, int arrayIndex) { }

        public bool Remove(TE item) => throw new NotSupportedException();

        public int Count { get; } = 0;

        public bool IsReadOnly { get; } = true;

        bool ISet<TE>.Add(TE item) => throw new NotSupportedException();

        public void ExceptWith(IEnumerable<TE> other) { }

        public void IntersectWith(IEnumerable<TE> other) { }

        public bool IsProperSubsetOf(IEnumerable<TE> other) => true;

        public bool IsProperSupersetOf(IEnumerable<TE> other) => false;

        public bool IsSubsetOf(IEnumerable<TE> other) => true;

        public bool IsSupersetOf(IEnumerable<TE> other) => !other.Any();

        public bool Overlaps(IEnumerable<TE> other) => false;

        public bool SetEquals(IEnumerable<TE> other) => !other.Any();

        public void SymmetricExceptWith(IEnumerable<TE> other) =>
            throw new NotSupportedException();

        public void UnionWith(IEnumerable<TE> other) =>
            throw new NotSupportedException();
    }
}